package com.itycu.server.service.business;

import java.util.List;
import com.itycu.server.utils.DateUtils;
import com.itycu.server.dto.business.FlowTodoDto;
import com.itycu.server.core.AbstractService;
import com.itycu.server.utils.SecurityUtils;
import javax.annotation.Resource;
import org.springframework.stereotype.Service;
import com.itycu.server.mapper.business.FlowTodoMapper;
import com.itycu.server.domain.business.FlowTodo;

/**
 * 流程记录Service业务层处理
 *
 * @author itycu
 * @date 2022-11-03
 */
@Service("flowTodoService")
public class FlowTodoService extends AbstractService<FlowTodo> {
    @Resource
    private FlowTodoMapper flowTodoMapper;

    /**
     * 查询流程记录列表
     *
     * @param flowTodo 流程记录
     * @return 流程记录
     */
    public List<FlowTodoDto> list(FlowTodo flowTodo) {
        flowTodo.setOrderByClause("id desc");
        return flowTodoMapper.listByCondition(flowTodo);
    }

    /**
     * 根据id获取流程记录详细信息
     */
    @Override
    public FlowTodoDto findById(Long id) {
        return flowTodoMapper.findById(id);
    }

    /**
     * 保存流程记录
     *
     * @param flowTodo 流程记录
     * @return 结果
     */
    @Override
    public int save(FlowTodo flowTodo) {
        int count;
        if (flowTodo.getId() == null) {
            flowTodo.setCreateTime(DateUtils.getNowDate());
            flowTodo.setCreateBy(SecurityUtils.getUserId());
            count = super.save(flowTodo);
        } else {
            flowTodo.setUpdateTime(DateUtils.getNowDate());
            count = super.update(flowTodo);
        }
        return count;
    }
}
